<template>
	<view class='page_cont'>
		<view class='check_wrap'>
			<view class='title'>学历要求</view>
			<view class='check_list'>
				<view class="check_item" :class="educat_index==-1?'active':''" @click="check_screen(-1,1)">不限</view>
				<view class="check_item" :class="educat_index==index?'active':''" v-for="(item,index) in educats" :key="index" @click="check_screen(index,1)">{{item.name}}</view>
			</view>
		</view>
		<view class='check_wrap'>
			<view class='title'>经验要求</view>
			<view class='check_list'>
				<view class="check_item" :class="exper_index==-1?'active':''" @click="check_screen(-1,2)">不限</view>
				<view class="check_item" :class="exper_index==index?'active':''" v-for="(item,index) in expers" :key="index" @click="check_screen(index,2)">{{item.name}}</view>
			</view>
		</view>
		<view class='check_wrap'>
			<view class='title'>期望薪资</view>
			<view class='check_list'>
				<view class="check_item" :class="wage_index==-1?'active':''" @click="check_screen(-1,3)">不限</view>
				<view class="check_item" :class="wage_index==index?'active':''" v-for="(item,index) in wages" :key="index" @click="check_screen(index,3)">{{item.name}}</view>
			</view>
		</view>
		<view class='check_wrap'>
			<view class='title'>工作性质</view>
			<view class='check_list'>
				<view class="check_item" :class="prop_index==-1?'active':''" @click="check_screen(-1,4)">不限</view>
				<view class="check_item" :class="prop_index==index?'active':''" v-for="(item,index) in props" :key="index" @click="check_screen(index,4)">{{item}}</view>
			</view>
		</view>
		<view class='btn_wrap'>
			<view class='del_btn' @click="delete_screen()">清除</view>
			<view class='con_btn' @click="confirm_screen()">确定</view>
		</view>
	</view>
</template>

<script>
	import home from "../../api/home.js"
	export default{
		data(){
			return {
				educats: [],
				educat_index: -2,
				expers: [],
				exper_index: -2,
				wages: [],
				wage_index: -2,
				props: ["全职","兼职"],
				prop_index: -2
			}
		},
		onLoad(options) {
			var that=this;
			var data=JSON.parse(options.data);
			that.educat_index=data.educat_index;
			that.exper_index=data.exper_index;
			that.wage_index=data.wage_index;
			that.prop_index=data.prop_index;
			//
			that.get_education_list();
			that.get_exper_list();
			that.get_salary_list();
		},
		methods: {
			// 选择
			check_screen(index,type){
				switch(type){
					case 1:
						this.educat_index=index;
						break;
					case 2:
						this.exper_index=index;
						break;
					case 3:
						this.wage_index=index;
						break;
					case 4:
						this.prop_index=index;
						break;
				}
			},
			// 清除
			delete_screen(){
				this.educat_index=-2;
				this.exper_index=-2;
				this.wage_index=-2;
				this.prop_index=-2;
				var pages = getCurrentPages();
				var prevPage = pages[pages.length - 2];
				prevPage.$vm.screening=true;
				prevPage.$vm.minimumEducationId='';
				prevPage.$vm.workExperienceId='';
				prevPage.$vm.salaryRangeMin='';
				prevPage.$vm.salaryRangeMax='';
				prevPage.$vm.positionNature='';
				prevPage.$vm.educat_index=-2;
				prevPage.$vm.exper_index=-2;
				prevPage.$vm.wage_index=-2;
				prevPage.$vm.prop_index=-2;
				// 返回
				// uni.navigateBack({
				// 	delta: 1
				// })
			},
			// 确定
			confirm_screen(){
				var pages = getCurrentPages();
				var prevPage = pages[pages.length - 2],change=false;
				var minimumEducationId=this.educat_index>=0?this.educats[this.educat_index].id:'',
					workExperienceId=this.exper_index>=0?this.expers[this.exper_index].id:'',
					salaryRangeMin=this.wage_index>=0?this.wages[this.wage_index].salaryRangeMin:'',
					salaryRangeMax=this.wage_index>=0?this.wages[this.wage_index].salaryRangeMax:'',
					positionNature=this.prop_index>=0?this.prop_index+1:'';
					
				if(prevPage.$vm.minimumEducationId != minimumEducationId){
					change=true;
				}
				if(prevPage.$vm.workExperienceId != workExperienceId){
					change=true;
				}
				if(prevPage.$vm.salaryRangeMin != salaryRangeMin){
					change=true;
				}
				if(prevPage.$vm.salaryRangeMax != salaryRangeMax){
					change=true;
				}
				if(prevPage.$vm.positionNature != positionNature){
					change=true;
				}
				console.log(change)
				if(change){
					prevPage.$vm.screening=true;
				}
				prevPage.$vm.minimumEducationId=minimumEducationId;
				prevPage.$vm.workExperienceId=workExperienceId;
				prevPage.$vm.salaryRangeMin=salaryRangeMin;
				prevPage.$vm.salaryRangeMax=salaryRangeMax;
				prevPage.$vm.positionNature=positionNature;
				prevPage.$vm.educat_index=this.educat_index;
				prevPage.$vm.exper_index=this.exper_index;
				prevPage.$vm.wage_index=this.wage_index;
				prevPage.$vm.prop_index=this.prop_index;
				//
				uni.navigateBack({
					delta: 1
				})
			},
			// 获取学历列表
			get_education_list(){
				home.get_education_list().then(res=>{
					this.educats=res.data.data;
				})
			},
			// 获取经验列表
			get_exper_list(){
				home.get_exper_list().then(res=>{
					this.expers=res.data.data;
				})
			},
			// 薪资范围列表
			get_salary_list(){
				home.get_salary_list().then(res=>{
					this.wages=res.data.data;
				})
			},
		},
	}
</script>

<style lang="scss">
	.page_cont{
		width: 100%;
		box-sizing: border-box;
		padding: 0 32rpx;
		.check_wrap{
			padding: 16rpx 0 12rpx 0;
			.title{
				text-align: left;
				height: 42rpx;
				font-size: 30rpx;
				font-weight: 600;
				line-height: 42rpx;
				color: #3F4A58;
				margin-bottom: 16rpx;
			}
			.check_list{
				width: 100%;
				overflow: hidden;
				.check_item{
					width: 212rpx;
					height: 80rpx;
					line-height: 80rpx;
					float: left;
					font-size: 28rpx;
					background: #F7F9FB;
					border-radius: 16rpx;
					font-weight: 400;
					text-align: center;
					margin-right: 24rpx;
					margin-bottom: 20rpx;
					color: #3F4A58;
					overflow: hidden;
					&:nth-child(3n){
						margin-right: 0;
					}
				}
				.active{
					color: #5B90FF;
					background: rgba(91,144,255,0.1);
				}
			}
		}
		.btn_wrap{
			display: flex;
			flex-direction: row;
			padding: 16rpx 0 48rpx 0;
			.del_btn{
				width: 212rpx;
				height: 104rpx;
				background:rgba(146,155,167,0.15);
				text-align: center;
				line-height: 104rpx;
				font-size: 36rpx;
				font-weight: 400;
				color:rgba(121,133,148,1);
				border-radius: 16rpx;
				margin-right: 26rpx;
			}
			.con_btn{
				flex: 1;
				height: 104rpx;
				background:rgba(91,144,255,1);
				text-align: center;
				line-height: 104rpx;
				font-size: 36rpx;
				font-weight: 400;
				color:#fff;
				border-radius: 16rpx;
			}
		}
	}
</style>
